package com.example.tallybook;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.example.tallybook.databinding.ActivityJiLuBinding;

import java.util.List;
import java.util.Objects;

public class JiLuActivity extends AppCompatActivity {
private ActivityJiLuBinding binding;
private RecyclerView view;
private List<Bean> date;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding = ActivityJiLuBinding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());
        Objects.requireNonNull(getSupportActionBar()).setTitle("查看");
        Objects.requireNonNull(getSupportActionBar()).setDisplayHomeAsUpEnabled(true);
        //接受传递过来的数据
        date = (List<Bean>) getIntent().getSerializableExtra("date");

        view = binding.rectangles;
        view.setLayoutManager(new LinearLayoutManager(this,RecyclerView.VERTICAL,false));
        view.setAdapter(new RecyclerView.Adapter<MyHoled>() {
            @NonNull
            @Override
            public MyHoled onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
                View view = View.inflate(parent.getContext(),R.layout.jil_idem,null);
                return new MyHoled(view);
            }

            @SuppressLint("SetTextI18n")
            @Override
            public void onBindViewHolder(@NonNull MyHoled holder, int position) {
                holder.t1.setText("时间："+ date.get(position).getTime());
                holder.t2.setText("消费方式：" + date.get(position).getSpinn());
                holder.t3.setText("地点：" + date.get(position).getDidian());
                holder.t4.setText("花费："+date.get(position).getMoney() + "元");
                holder.t5.setText("备注：" + date.get(position).getBeizhu());
            }

            @Override
            public int getItemCount() {
                return date.size();
            }
        });









    }
    @Override
    public boolean onOptionsItemSelected(@NonNull MenuItem item) {
        if (item.getItemId() == android.R.id.home) {
            finish();
        }
        return super.onOptionsItemSelected(item);
    }
    private class MyHoled extends RecyclerView.ViewHolder{
        TextView t1,t2,t3,t4,t5;
        public MyHoled(@NonNull View itemView) {
            super(itemView);
            t1 = itemView.findViewById(R.id.sj);
            t2 = itemView.findViewById(R.id.wx);
            t3 = itemView.findViewById(R.id.dd);
            t4 = itemView.findViewById(R.id.xf);
            t5 = itemView.findViewById(R.id.bz);
        }
    }
}